<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="assets/css/bootstrap.css" />
    <link href="assets/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="./assets/css/bootstrap-treeview.css" media="all">

    <script src="assets/js/jquery-2.0.3.min.js"></script>
    <script src="assets/js/bootstrap.js"></script>
    <script src="assets/js/utils.js"></script>
    <script src="assets/js/bootstrap-treeview.js"></script>
    <script src="assets/layer/layer.js"></script>
</head>

<body>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <div class="main-content">
            <div class="page-content">
                <div style="padding: 0px 15px;">

                    <div class="row">
                        <hr>
                        <div class="col-sm-4">
                            <div id="treeview1" class=""></div>
                        </div>
                        <div class="col-sm-8">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default" id="fle">刷新</button>
                                <button type="button" class="btn btn-success" id="add">新增</button>
                                <button type="button" class="btn btn-primary" id="upd">修改</button>
                                <button type="button" class="btn btn-danger" id="del">删除</button>
                            </div>
                            <hr>
                            <input type="hidden" id="id">
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td>机构名称</td>
                                    <td id="orgName"></td>
                                    <td>机构编码</td>
                                    <td id="orgCode"></td>
                                </tr>
                                <tr>
                                    <td>联系人</td>
                                    <td id="master"></td>
                                    <td>联系电话</td>
                                    <td id="phone"></td>
                                </tr>
                                <tr>
                                    <td>地址</td>
                                    <td id="address"></td>
                                    <td>备注</td>
                                    <td id="remark"></td>
                                </tr>
                                <tr >
                                    <td>创建人</td>
                                    <td id="cuser"></td>
                                    <td>创建时间</td>
                                    <td id="ctime"></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function() {
        initTree();

        $("#fle").click(function(){
            initTree();
        });
        $("#add").click(function(){
            var myId = $("#id").val();
            var selecttree = $('#treeview1').treeview('getSelected');
            var myName = '';
            console.log(selecttree);
            if(JSON.stringify(selecttree)!='[]'){
                myName = selecttree[0].text;
            }
            $.FormDialog({
                form_url : './dOrgAdd?myName='+myName,
                title : '新增机构信息',
                id : myId
            });
        });
        $("#upd").click(function(){
            var myId = $("#id").val();
            if(myId!=null && myId!=="" && myId!=="undefined") {
                layer.msg('是否修改？', {
                    time: 0 //不自动关闭
                    , btn: ['确定', '取消']
                    , yes: function (index) {
                        layer.close(index);
                        $.FormDialog({
                            form_url : './dOrgUpdate',
                            title : '修改机构信息',
                            id : myId
                        });
                    }
                });
            }
        });
        $("#del").click(function(){
            var myId = $("#id").val();
            if(myId!=null && myId!=="" && myId!=="undefined") {
                layer.msg('是否删除？', {
                    time: 0 //不自动关闭
                    , btn: ['确定', '取消']
                    , yes: function (index) {
                        layer.close(index);
                        ajaxs('./DOrg/' + myId, 'DELETE', null, true, function (data) {
                            if (data.state == "success") {
                                layer.msg(data.message, {icon: 6});
                                initTree();
                            } else if (data.typecode == "error") {
                                layer.msg(data.message, {icon: 5});
                            } else {
                                layer.msg(data.message, {icon: 3});
                            }
                        });
                    }
                });
            }
        });
    });
    function initTree() {
        $("#id").val("");
        cleanHtml();
        ajaxs('./DOrg/getOrgTree', 'GET', null, true, function (data) {
            $('#treeview1').treeview({
                data: data
            });
        });
    }
    function itemOnclick(target) {
        //找到当前节点id
        var nodeid = $(target).attr('data-nodeid');
        var tree = $('#treeview1');
        //获取当前节点对象
        var node = tree.treeview('getNode', nodeid);
        var myId = node.myId;
        var myIdOld = $("#id").val();
        if(myId==myIdOld){
            cleanHtml();
            $("#id").val("");
        }else {
            ajaxs('./DOrg/searchByCode/'+myId, 'GET', null, true, function (data) {
                $("#orgName").html(data.orgName);
                $("#orgCode").html(data.orgCode);
                $("#master").html(data.orgUser);
                $("#phone").html(data.orgPhone);
                $("#address").html(data.orgAddress);
                $("#remark").html(data.remark);
                $("#cuser").html(data.updateUser);
                $("#ctime").html(data.extender.showUpdateTime);
                $("#id").val(myId);
            });
        }
    }
    function cleanHtml() {
        $("#orgName").html('');
        $("#orgCode").html('');
        $("#master").html('');
        $("#phone").html('');
        $("#address").html('');
        $("#remark").html('');
        $("#cuser").html('');
        $("#ctime").html('');
        $("#id").val('');
    }
</script>
</body>

</html>